<script setup>
import {ref,onMounted} from "vue";
import { getNavList } from "@/api/index";
const showChoice = ref(false);
const navList = ref();
// 获取banner图列表
const getnavList = async () => {  //同步调用
    const {
        data: { data },
    } = await getNavList();
    console.log(data.child);
    navList.value = data;
    // console.log(navList);
};
onMounted(()=>{
    getnavList();
})
</script>

<template>
    <div id="app">
        <div class="nav">
            <div class="navcenter">
                <div class="navcenter1">
                    <div class="navtop"><img src="./assets/sucai/xuexiao2.png" alt=""></div>
                    <div class="xiala"  @click="showChoice = !showChoice"><img src="./assets/image/fen.png" alt=""></div>
                </div>
                <ul class="top-nav">
                    <li>
                        <router-link exact to="/">首页</router-link>
                    </li>
                    <li>
                        <router-link to="/about">院部简介</router-link>
                    </li>
                    <li  v-for="item in navList" :key="item.id">
                        <router-link to="/home">
                            {{ item.title }}
                            <div class="lichild" v-for="item1 in item.child" :key="item1">
                                <router-link to="/about">
                                    <div class="lichild1">{{ item1.title }}</div>
                                </router-link>
                            </div>
                        </router-link>
                    </li>
                    <!-- <li>
                        <router-link to="/home">专业介绍</router-link>
                    </li> -->
                    <li>
                        <router-link to="/about">领导关怀</router-link>
                    </li>
                    <li>
                        <router-link to="/home">对外交流</router-link>
                    </li>
                    <li>
                        <router-link to="/about">社会服务</router-link>
                    </li>
                    <li>
                        <router-link to="/home">师资力量</router-link>
                    </li>
                    <li>
                        <router-link to="/about">实训中心</router-link>
                    </li>
                    <li>
                        <router-link to="/about">实习基地</router-link>
                    </li>
                </ul>
                <ul class="top-nav1" v-show="showChoice">
                    <li  @click="showChoice = !showChoice">
                        <router-link exact to="/">首页</router-link>
                    </li>
                    <li  @click="showChoice = !showChoice">
                        <router-link to="/about">院部简介</router-link>
                    </li>
                    <li  @click="showChoice = !showChoice">
                        <router-link to="/home">办学特色</router-link>
                    </li>
                    <li  @click="showChoice = !showChoice">
                        <router-link to="/home">专业介绍</router-link>
                    </li>
                    <li  @click="showChoice = !showChoice">
                        <router-link to="/about">领导关怀</router-link>
                    </li>
                    <li  @click="showChoice = !showChoice">
                        <router-link to="/home">对外交流</router-link>
                    </li>
                    <li  @click="showChoice = !showChoice">
                        <router-link to="/about">社会服务</router-link>
                    </li>
                    <li  @click="showChoice = !showChoice">
                        <router-link to="/home">师资力量</router-link>
                    </li>
                    <li  @click="showChoice = !showChoice">
                        <router-link to="/about">实训中心</router-link>
                    </li>
                    <li  @click="showChoice = !showChoice">
                        <router-link to="/about">实习基地</router-link>
                    </li>
                </ul>
            </div>
        </div>
        <router-view />
    </div>
    <!-- <nav>
        <RouterLink to="/">index</RouterLink>
        <RouterLink to="/home">Home</RouterLink>
        <RouterLink to="/about">About</RouterLink>
    </nav>

    <RouterView /> -->
</template>

<style lang="scss">
* {
    margin: 0;
    padding: 0;
}

#app {
    .nav {
        background: rgba(105, 1, 2, 0.8);
        z-index: 999;

        .navcenter {
            width: 80%;
            margin: auto;
            display: flex;

            @media (max-width:475px) {
                display: block;
                width: 100%;
                position: relative;
            }

            .navcenter1 {
                @media (max-width:475px) {
                    width: 90%;
                    margin: auto;
                    display: flex;
                    justify-content: space-between;
                }
                .navtop {
                    padding: 10px 0;

                    img {
                        height: 60px;

                        @media (max-width:475px) {
                            width: 150px;
                            height: 40px;
                        }
                    }
                }

                .xiala {
                    display: none;

                    @media (max-width: 475px) {
                        display: block;
                        margin-top: 10px;
                        img {
                            width: 30px;
                            height: 30px;
                        }
                    }
                }
            }

            .top-nav {
                display: flex;
                width: 100%;

                @media (max-width:1024px) {
                    display: none;
                    // height: 440px;
                    // background-color: rgba(0, 0, 0, 0.6);
                    // position: absolute;
                    // top: 60px;
                    // z-index: 999;
                }

                li {
                    list-style: none;
                    flex: 1;
                    text-align: center;
                    padding-top: 10px;
                    z-index: 999;
                    @media (max-width: 475px) {
                        // display: none;
                        line-height: 40px;
                        height: 40px;
                        width: 100%;
                        font-size: 12px;
                        text-align: left;
                    }
                    .lichild{
                        display: none;
                        z-index: 999;
                        width: 140px;
                        background-color: rgba(0, 0, 0, 0.6);
                        a{
                            width: 100%
                        }
                    }
                    &:hover .lichild{
                        display: block;
                        margin-left: -38%;
                    }
                    a {
                        text-decoration: none;
                        display: block;
                        padding-bottom: 8px;
                        color: #fff;
                        width: 80px;
                        height: 60px;
                        margin: auto;
                        line-height: 60px;

                        @media (max-width:475px) {
                            width: 90%;
                            margin: auto;
                        }

                        &:hover {
                            border-bottom: 4px solid #005bac;
                        }
                    }
                }
            }
            .top-nav1 {
                display: flex;
                width: 100%;
                display: none;
                @media (max-width:475px) {
                    display: block;
                    height: 440px;
                    background-color: rgba(0, 0, 0, 0.6);
                    position: absolute;
                    top: 60px;
                    z-index: 999;
                }

                li {
                    list-style: none;
                    flex: 1;
                    text-align: center;
                    padding-top: 10px;

                    @media (max-width: 475px) {
                        // display: none;
                        line-height: 40px;
                        height: 40px;
                        width: 100%;
                        font-size: 12px;
                        
                        text-align: left;
                    }

                    a {
                        text-decoration: none;
                        display: block;
                        padding-bottom: 8px;
                        color: #fff;
                        width: 80px;
                        height: 60px;
                        margin: auto;
                        line-height: 60px;

                        @media (max-width:475px) {
                            width: 90%;
                            margin: auto;
                        }

                        &:hover {
                            border-bottom: 4px solid #005bac;
                        }
                    }
                }
            }
        }
    }
}
</style>
